package com.schoolcloud.social.controller.event;

import com.schoolcloud.common.model.R;
import com.schoolcloud.social.entity.SocEventConditionValues;
import com.schoolcloud.social.entity.SocEventConditionsTypes;
import com.schoolcloud.social.service.SocEventConditionValuesService;
import com.schoolcloud.social.service.SocEventConditionsTypesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("social/event/condition")
@RequiredArgsConstructor
public class SocEventConditionController {
    private final SocEventConditionsTypesService socEventConditionsTypesService;
    private final SocEventConditionValuesService socEventConditionValuesService;

    @PostMapping("/type")
    public R addEventConditionType(@RequestBody SocEventConditionsTypes eventConditionsTypes) {
        socEventConditionsTypesService.addEventCondition(eventConditionsTypes);
        return R.ok();
    }

    @GetMapping("/type/list")
    public R<List<SocEventConditionsTypes>> getEventConditionTypesList() {
        return R.ok(socEventConditionsTypesService.list());
    }

    @PutMapping("/type")
    public R modifyEventConditionTypes(@RequestBody SocEventConditionsTypes eventConditionsTypes) {
        return R.ok(socEventConditionsTypesService.save(eventConditionsTypes));
    }

    @DeleteMapping("/type/{conditionTypeId}")
    public R deleteEventConditionTypes(@PathVariable String conditionTypeId) {
        return R.ok(socEventConditionsTypesService.removeById(conditionTypeId));
    }
    @PostMapping("/value")
    public R addEventConditionValue(@RequestBody SocEventConditionValues values) {
        socEventConditionValuesService.save(values);
        return R.ok();
    }

    @GetMapping("/value/list")
    public R<List<SocEventConditionValues>> getEventConditionValuesList() {
        return R.ok(socEventConditionValuesService.list());
    }

    @PutMapping("/value")
    public R modifyEventConditionValues(@RequestBody SocEventConditionValues values) {
        return R.ok(socEventConditionValuesService.save(values));
    }

    @DeleteMapping("/values/{conditionValueId}")
    public R deleteEventConditionValue(@PathVariable String conditionValueId) {
        return R.ok(socEventConditionValuesService.removeById(conditionValueId));
    }
}
